package com.xuzz.study.spring.simplemvc.demo;

import com.xuzz.study.spring.simplemvc.annotation.XzzAutowired;
import com.xuzz.study.spring.simplemvc.annotation.XzzController;
import com.xuzz.study.spring.simplemvc.annotation.XzzRequestMapping;
import com.xuzz.study.spring.simplemvc.annotation.XzzRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@XzzController
@XzzRequestMapping("/demo")
public class DemoController {

    @XzzAutowired
    IDemoService demoService;

    @XzzRequestMapping("/get.json")
    public void query(HttpServletRequest req, HttpServletResponse resp, @XzzRequestParam("name") String name)
    {
        String result = demoService.get(name);
        try
        {
            resp.getWriter().write(result);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @XzzRequestMapping("/add.json")
    public void add(HttpServletRequest req, HttpServletResponse resp, @XzzRequestParam("a") Integer a, @XzzRequestParam("b") Integer b)
    {
        try
        {
            resp.getWriter().write(a+"+"+b+"="+(a+b));
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @XzzRequestMapping("/remove.json")
    public void remove(HttpServletRequest req, HttpServletResponse resp)
    {
    }

}
